import { ref } from 'vue';

import { routerTo } from '@/utils/jump';

export const link_list = [
    {
        id: 1,
        icon: '/icon/home.svg',
        active_icon: '/icon/home-active.svg',
        text: 'Home',
        link: '/',
        click: () => {
            routerTo('/');
            active_nav_item.value = link_list[0];
        }
    },
    {
        id: 2,
        icon: '/icon/asset.svg',
        active_icon: '/icon/asset-active.svg',
        text: 'Assets',
        link: '/asset',
        click: () => {
            routerTo('/asset');
            active_nav_item.value = link_list[1];
        }
    },
    {
        id: 3,
        icon: '/icon/markets.svg',
        active_icon: '/icon/markets-active.svg',
        text: 'Markets',
        link: '/market',
        click: () => {
            routerTo('/market');
            active_nav_item.value = link_list[2];
        }
    },
    {
        id: 4,
        icon: '/icon/trade.svg',
        active_icon: '/icon/trade-active.svg',
        text: 'Trade',
        link: '/trade',
        click: () => {
            routerTo('/trade');
            active_nav_item.value = link_list[3];
        }
    },
    {
        id: 5,
        icon: '/icon/deposit.svg',
        active_icon: '/icon/deposit-active.svg',
        text: 'Deposit / Withdraw',
        link: '/deposit',
        click: () => {
            routerTo('/deposit');
            active_nav_item.value = link_list[4];
        }
    },
];

export const active_nav_item = ref(link_list[0]);

export function get_active_nav_item() {
    // 获取当前页面的path
    let path = window.location.pathname;
    // 去掉最后一个 '/' 字符
    if (path.length > 1 && path[path.length - 1] == '/') path = path.slice(0, path.length - 1);
    // 匹配路由
    for (let i = 0; i < link_list.length; i++) {
        let item = link_list[i];
        if (item.link == path) {
            active_nav_item.value = item;
            break;
        }
    }
}